import { AppDataSource } from '../../db/index'
import { Tag } from '../../db/entities/Tag'

const tagRepository = AppDataSource.getRepository(Tag)

/**
 * 查询所有标签
 */
export default defineEventHandler(async (event) => {
  let body = await readBody(event)

  let currentPage = Number(body.currentPage) || 1
  let pageSize = Number(body.pageSize) || 10

  let res = await tagRepository.findAndCount({
    skip: (currentPage - 1) * pageSize,
    take: pageSize
  })

  console.log(res)

  return {
    code: 0,
    data: {
      list: res[0],
      total: res[1]
    },
    message: 'success'
  }
})
